package com.ruoyi.purchase.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.purchase.domain.TPurchase;
import com.ruoyi.purchase.service.ITPurchaseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 团购管理Controller
 * 
 * @author ruoyi
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/purchase")
public class TPurchaseController extends BaseController
{
    @Autowired
    private ITPurchaseService tPurchaseService;

    /**
     * 查询团购管理列表
     */
    @RequiresPermissions("purchase:purchase:list")
    @GetMapping("/list")
    public TableDataInfo list(TPurchase tPurchase)
    {
        startPage();
        List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
        return getDataTable(list);
    }

    /**
     * 导出团购管理列表
     */
    @RequiresPermissions("purchase:purchase:export")
    @Log(title = "团购管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPurchase tPurchase)
    {
        List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
        ExcelUtil<TPurchase> util = new ExcelUtil<TPurchase>(TPurchase.class);
        util.exportExcel(response, list, "团购管理数据");
    }

    /**
     * 获取团购管理详细信息
     */
    @RequiresPermissions("purchase:purchase:query")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return success(tPurchaseService.selectTPurchaseByPurchaseId(purchaseId));
    }

    /**
     * 新增团购管理
     */
    @RequiresPermissions("purchase:purchase:add")
    @Log(title = "团购管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPurchase tPurchase)
    {
        return toAjax(tPurchaseService.insertTPurchase(tPurchase));
    }

    /**
     * 修改团购管理
     */
    @RequiresPermissions("purchase:purchase:edit")
    @Log(title = "团购管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPurchase tPurchase)
    {
        return toAjax(tPurchaseService.updateTPurchase(tPurchase));
    }

    /**
     * 删除团购管理
     */
    @RequiresPermissions("purchase:purchase:remove")
    @Log(title = "团购管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseIds)
    {
        return toAjax(tPurchaseService.deleteTPurchaseByPurchaseIds(purchaseIds));
    }
}
